package com.qingge.springboot.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qingge.springboot.common.Result;
import com.qingge.springboot.entity.Paper;
import com.qingge.springboot.entity.Test;
import com.qingge.springboot.service.ITestService;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/test")
public class TestController {


    @Resource
    private ITestService testService;



    @GetMapping
    public Result getPaper(@RequestParam Integer pageSize, @RequestParam Integer pageNum, @RequestParam(required = false) String title){
        LambdaQueryWrapper<Test> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtils.hasLength(title),Test::getContent,title);
        return Result.success(testService.page(new Page<>(pageNum,pageSize), queryWrapper));
    }

    @PostMapping
    public Result save(@RequestBody Test test){
        testService.save(test);
        return Result.success();
    }


}
